var _jsroot =  location.origin + window.Think.ROOT + '/Public/static/';
var _jsver = '20160325';
//js别名 用于think.use();方法
var _jsalias = {
            thinkbox           : 'thinkbox/jquery.thinkbox',
            jquery             : 'jquery-2.0.3.min',  
            ajaxForm           : 'js/ajaxForm',  
            formvalidate       :'formValidator4.min',
            artDialog5         : 'artDialog5/jquery.artDialog.min',
            artDialog6         : 'artDialog6/dialog-plus-min',
			datetimepicker     : 'datetimepicker/js/bootstrap-datetimepicker',
            xd                 : 'xd',//Iframe跨域通信   
            uploadify          : 'uploadify/jquery.uploadify',
			listTable          : 'js/listTable',
			swfupload          : 'swfupload/swfupload',
			dragsort           :'js/jquery.dragsort-0.5.2.min',
			datepicker         :'My97DatePicker/WdatePicker'
		};

//css别名 用于think.use();方法加载js库对应的css
var _cssalias = {
            artDialog5     : 'artDialog5/skins/black',
			datetimepicker :'datetimepicker/css/datetimepicker',
            artDialog6   : 'artDialog6/css/ui-dialog'            
		};
/* 扩展ThinkPHP对象 */
(function($){
	/**
	 * 获取ThinkPHP基础配置
	 * @type {object}
	 */
	var ThinkPHP = window.Think;
 
	/* 基础对象检测 */
	ThinkPHP || $.error("ThinkPHP基础配置没有正确加载！");
    
	/**
	 * 解析URL
	 * @param  {string} url 被解析的URL
	 * @return {object}     解析后的数据
	 */
	ThinkPHP.parse_url = function(url){
		var parse = url.match(/^(?:([a-z]+):\/\/)?([\w-]+(?:\.[\w-]+)+)?(?::(\d+))?([\w-\/\.]+)?(?:\?((?:\w+=[^#&=\/]*)?(?:&\w+=[^#&=\/]*)*))?(?:#([\w-]+))?$/i);
		parse || $.error("url格式不正确！");
		return {
			"scheme"   : parse[1],
			"host"     : parse[2],
			"port"     : parse[3],
			"path"     : parse[4],
			"query"    : parse[5],
			"fragment" : parse[6]
		};
	};

	ThinkPHP.parse_str = function(str){
		var value = str.split("&"), vars = {}, param;
		for(val in value){
			param = value[val].split("=");
			vars[param[0]] = param[1];
		}
		return vars;
	};

	ThinkPHP.parse_name = function(name, type){
		if(type){
			/* 下划线转驼峰 */
			name.replace(/_([a-z])/g, function($0, $1){
				return $1.toUpperCase();
			});

			/* 首字母大写 */
			name.replace(/[a-z]/, function($0){
				return $0.toUpperCase();
			});
		} else {
			/* 大写字母转小写 */
			name = name.replace(/[A-Z]/g, function($0){
				return "_" + $0.toLowerCase();
			});

			/* 去掉首字符的下划线 */
			if(0 === name.indexOf("_")){
				name = name.substr(1);
			}
		}
		return name;
	};

	//scheme://host:port/path?query#fragment
	ThinkPHP.U = function(url, vars, suffix){
		var info = this.parse_url(url), path = [], param = {}, reg;

		/* 验证info */
		info.path || $.error("url格式错误！");
		url = info.path;

		/* 组装URL */
		if(0 === url.indexOf("/")){ //路由模式
			this.MODEL[0] == 0 && $.error("该URL模式不支持使用路由!(" + url + ")");

			/* 去掉右侧分割符 */
			if("/" == url.substr(-1)){
				url = url.substr(0, url.length -1)
			}
			url = ("/" == this.DEEP) ? url.substr(1) : url.substr(1).replace(/\//g, this.DEEP);
			url = "/" + url;
		} else { //非路由模式
			/* 解析URL */
			path = url.split("/");
			path = [path.pop(), path.pop(), path.pop()].reverse();
			path[1] || $.error("ThinkPHP.U(" + url + ")没有指定控制器");

			if(path[0]){
				param[this.VAR[0]] = this.MODEL[1] ? path[0].toLowerCase() : path[0];
			}

			param[this.VAR[1]] = this.MODEL[1] ? this.parse_name(path[1]) : path[1];
			param[this.VAR[2]] = path[2].toLowerCase();

			url = "?" + $.param(param);
		}

		/* 解析参数 */
		if(typeof vars === "string"){
			vars = this.parse_str(vars);
		} else if(!$.isPlainObject(vars)){
			vars = {};
		}

		/* 解析URL自带的参数 */
		info.query && $.extend(vars, this.parse_str(info.query));

		if(vars){
			url += "&" + $.param(vars);
		}

		if(0 != this.MODEL[0]){
			url = url.replace("?" + (path[0] ? this.VAR[0] : this.VAR[1]) + "=", "/")
				     .replace("&" + this.VAR[1] + "=", this.DEEP)
				     .replace("&" + this.VAR[2] + "=", this.DEEP)
				     .replace(/(\w+=&)|(&?\w+=$)/g, "")
				     .replace(/[&=]/g, this.DEEP);

			/* 添加伪静态后缀 */
			if(false !== suffix){
				suffix = suffix || this.MODEL[2].split("|")[0];
				if(suffix){
					url += "." + suffix;
				}
			}
		}

		url = this.APP + url;
		return url;
	};

	/* 设置表单的值 */
	ThinkPHP.setValue = function(name, value){
		var first = name.substr(0,1), input, i = 0, val;
		if(value === "") return;
		if("#" === first || "." === first){
			input = $(name);
		} else {
			input = $("[name='" + name + "']");
		}

		if(input.eq(0).is(":radio")) { //单选按钮
			input.filter("[value='" + value + "']").each(function(){this.checked = true});
		} else if(input.eq(0).is(":checkbox")) { //复选框
			if(!$.isArray(value)){
				val = new Array();
				val[0] = value;
			} else {
				val = value;
			}
			for(i = 0, len = val.length; i < len; i++){
				input.filter("[value='" + val[i] + "']").each(function(){this.checked = true});
			}
		} else {  //其他表单选项直接设置值
			input.val(value);
		}
	};

  $.fn.getValueList=function(){		
		 	var tmpArr=[];		 	
		   $(this).each(function(i,sel){ 	
	        	if($(sel).prop("checked")){    
	        		 tmpArr.push($(sel).val());
	        	 }        	
	       });  
	       return tmpArr.join(",");
	};

   window.ThinkPHP=ThinkPHP;
})(jQuery);
/*! head.load - v1.0.3 */
(function(n,t){"use strict";function w(){}function u(n,t){if(n){typeof n=="object"&&(n=[].slice.call(n));for(var i=0,r=n.length;i<r;i++)t.call(n,n[i],i)}}function it(n,i){var r=Object.prototype.toString.call(i).slice(8,-1);return i!==t&&i!==null&&r===n}function s(n){return it("Function",n)}function a(n){return it("Array",n)}function et(n){var i=n.split("/"),t=i[i.length-1],r=t.indexOf("?");return r!==-1?t.substring(0,r):t}function f(n){(n=n||w,n._done)||(n(),n._done=1)}function ot(n,t,r,u){var f=typeof n=="object"?n:{test:n,success:!t?!1:a(t)?t:[t],failure:!r?!1:a(r)?r:[r],callback:u||w},e=!!f.test;return e&&!!f.success?(f.success.push(f.callback),i.load.apply(null,f.success)):e||!f.failure?u():(f.failure.push(f.callback),i.load.apply(null,f.failure)),i}function v(n){var t={},i,r;if(typeof n=="object")for(i in n)!n[i]||(t={name:i,url:n[i]});else t={name:et(n),url:n};return(r=c[t.name],r&&r.url===t.url)?r:(c[t.name]=t,t)}function y(n){n=n||c;for(var t in n)if(n.hasOwnProperty(t)&&n[t].state!==l)return!1;return!0}function st(n){n.state=ft;u(n.onpreload,function(n){n.call()})}function ht(n){n.state===t&&(n.state=nt,n.onpreload=[],rt({url:n.url,type:"cache"},function(){st(n)}))}function ct(){var n=arguments,t=n[n.length-1],r=[].slice.call(n,1),f=r[0];return(s(t)||(t=null),a(n[0]))?(n[0].push(t),i.load.apply(null,n[0]),i):(f?(u(r,function(n){s(n)||!n||ht(v(n))}),b(v(n[0]),s(f)?f:function(){i.load.apply(null,r)})):b(v(n[0])),i)}function lt(){var n=arguments,t=n[n.length-1],r={};return(s(t)||(t=null),a(n[0]))?(n[0].push(t),i.load.apply(null,n[0]),i):(u(n,function(n){n!==t&&(n=v(n),r[n.name]=n)}),u(n,function(n){n!==t&&(n=v(n),b(n,function(){y(r)&&f(t)}))}),i)}function b(n,t){if(t=t||w,n.state===l){t();return}if(n.state===tt){i.ready(n.name,t);return}if(n.state===nt){n.onpreload.push(function(){b(n,t)});return}n.state=tt;rt(n,function(){n.state=l;t();u(h[n.name],function(n){f(n)});o&&y()&&u(h.ALL,function(n){f(n)})})}function at(n){n=n||"";var t=n.split("?")[0].split(".");return t[t.length-1].toLowerCase()}function rt(t,i){function e(t){t=t||n.event;u.onload=u.onreadystatechange=u.onerror=null;i()}function o(f){f=f||n.event;(f.type==="load"||/loaded|complete/.test(u.readyState)&&(!r.documentMode||r.documentMode<9))&&(n.clearTimeout(t.errorTimeout),n.clearTimeout(t.cssTimeout),u.onload=u.onreadystatechange=u.onerror=null,i())}function s(){if(t.state!==l&&t.cssRetries<=20){for(var i=0,f=r.styleSheets.length;i<f;i++)if(r.styleSheets[i].href===u.href){o({type:"load"});return}t.cssRetries++;t.cssTimeout=n.setTimeout(s,250)}}var u,h,f;i=i||w;h=at(t.url);h==="css"?(u=r.createElement("link"),u.type="text/"+(t.type||"css"),u.rel="stylesheet",u.href=t.url,t.cssRetries=0,t.cssTimeout=n.setTimeout(s,500)):(u=r.createElement("script"),u.type="text/"+(t.type||"javascript"),u.src=t.url);u.onload=u.onreadystatechange=o;u.onerror=e;u.async=!1;u.defer=!1;t.errorTimeout=n.setTimeout(function(){e({type:"timeout"})},7e3);f=r.head||r.getElementsByTagName("head")[0];f.insertBefore(u,f.lastChild)}function vt(){for(var t,u=r.getElementsByTagName("script"),n=0,f=u.length;n<f;n++)if(t=u[n].getAttribute("data-headjs-load"),!!t){i.load(t);return}}function yt(n,t){var v,p,e;return n===r?(o?f(t):d.push(t),i):(s(n)&&(t=n,n="ALL"),a(n))?(v={},u(n,function(n){v[n]=c[n];i.ready(n,function(){y(v)&&f(t)})}),i):typeof n!="string"||!s(t)?i:(p=c[n],p&&p.state===l||n==="ALL"&&y()&&o)?(f(t),i):(e=h[n],e?e.push(t):e=h[n]=[t],i)}function e(){if(!r.body){n.clearTimeout(i.readyTimeout);i.readyTimeout=n.setTimeout(e,50);return}o||(o=!0,vt(),u(d,function(n){f(n)}))}function k(){r.addEventListener?(r.removeEventListener("DOMContentLoaded",k,!1),e()):r.readyState==="complete"&&(r.detachEvent("onreadystatechange",k),e())}var r=n.document,d=[],h={},c={},ut="async"in r.createElement("script")||"MozAppearance"in r.documentElement.style||n.opera,o,g=n.head_conf&&n.head_conf.head||"ThinkPHP",i=n[g]=n[g]||function(){i.ready.apply(null,arguments)},nt=1,ft=2,tt=3,l=4,p;if(r.readyState==="complete")e();else if(r.addEventListener)r.addEventListener("DOMContentLoaded",k,!1),n.addEventListener("load",e,!1);else{r.attachEvent("onreadystatechange",k);n.attachEvent("onload",e);p=!1;try{p=!n.frameElement&&r.documentElement}catch(wt){}p&&p.doScroll&&function pt(){if(!o){try{p.doScroll("left")}catch(t){n.clearTimeout(i.readyTimeout);i.readyTimeout=n.setTimeout(pt,50);return}e()}}()}i.load=i.js=ut?lt:ct;i.test=ot;i.ready=yt;i.ready(r,function(){y()&&u(h.ALL,function(n){f(n)});i.feature&&i.feature("domloaded",!0)})})(window);

/*
 * 防止浏览器不支持console报错
 */
if(!window.console) {
    window.console = {};
    var funs = ["profiles", "memory", "_commandLineAPI", "debug", "error", "info", "log", "warn", "dir", "dirxml", "trace", "assert", "count", "markTimeline", "profile", "profileEnd", "time", "timeEnd", "timeStamp", "group", "groupCollapsed", "groupEnd"];
    for(var i = 0;i < funs.length; i++) {
        console[funs[i]] = function() {};
    }
}
/*
*解决ie6下不支持背景缓存
*/
ThinkPHP.ready(function() {
	if (!+'\v1' && !('maxHeight' in document.body.style)) {
		try{
			document.execCommand("BackgroundImageCache", false, true);
		}catch(e){}
	}
});

/*
*core
*/
(function(win) {
      var ver=_jsver,root=_jsroot,
		//定义常用JS组件别名，使用别名加载
		alias = _jsalias, 
        //CSS路径
		alias_css = _cssalias;
	//add suffix and version
	for(var i in alias) {
		if (alias.hasOwnProperty(i)) {
			alias[i] = root + alias[i] +'.js?v=' + ver;
		}
	}

	for(var i in alias_css) {
		if (alias_css.hasOwnProperty(i)) {
			alias_css[i] = root + alias_css[i] +'.css?v=' + ver;
		}
	}

	//css loader
	win.ThinkPHP = win.ThinkPHP || {};
    //!TODO old webkit and old firefox does not support
	ThinkPHP.css = function(alias/*alias or path*/,callback) {
		var url = alias_css[alias] ? alias_css[alias] : alias
		var link = document.createElement('link');
        link.rel = 'stylesheet';
        link.href = url;
        link.onload = link.onreadystatechange = function() {//chrome link无onload事件
            var state = link.readyState;
            if (callback && !callback.done && (!state || /loaded|complete/.test(state))) {
                callback.done = true;
                callback();
            }
        }
        document.getElementsByTagName('head')[0].appendChild(link);
	};
	//Using the alias to load the script file
	ThinkPHP.use = function() {
		var args = arguments,len = args.length;
        for( var i = 0;i < len;i++ ) {
           if(typeof args[i] === 'string' && alias_css[args[i]]) {
                     ThinkPHP.css(args[i],function(){});
            }
        	if(typeof args[i] === 'string' && alias[args[i]]) {
        		args[i] = alias[args[i]];
        	}
        }
		ThinkPHP.js.apply(null,args);
	};

})(window);

(function(win){
	win.ThinkPHP = win.ThinkPHP || {};
    //javascript template (author: John Resig http://ejohn.org/blog/javascript-micro-templating/)
    var _formatJson_cache = {};
    ThinkPHP.template = function(tpl,data,isHtml) {  
        var str='';     
        if(typeof tpl === "string"){    
            isHtml= isHtml || false;
            str=(isHtml === true)?tpl:$('#'+tpl).html();          
        }else{
            str = tpl.html();
        }   
        return ThinkPHP.tmpl(str,data);     
    };    
    ThinkPHP.tmpl = function tmpl(str, data){
     var fn = !/\W/.test(str) ?_formatJson_cache[str] = _formatJson_cache[str] ||ThinkPHP.tmpl(document.getElementById(str).innerHTML) :
      new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};" +"with(obj){p.push('" +str.replace(/[\r\t\n]/g, " ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g, "$1\r").replace(/\t=(.*?)%>/g, "',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+ "');}return p.join('');");   
    return data ? fn( data ) : fn;
  };

})(window);

(function(win){
	win.ThinkPHP = win.ThinkPHP || {};
	ThinkPHP.confirm=function(msg,okfun,cancelfun){
		data={title:"请确认",content:msg,cancelValue:"取消",okValue:"确定",time:0};	 
		data.ok=($.isFunction(okfun))?okfun:function(){};
		data.cancel=($.isFunction(cancelfun))?cancelfun:function(){};      
        d=$.dialog(data); 
		return d;
	};
	ThinkPHP.tips=function(msg){	
	     data={title:'提示',content:msg,time:1000};
	     $.dialog(data);
	};	
	ThinkPHP.alert=function(msg){
		data={title:"信息",content:msg,okValue:"确定",ok:function(){}};
		$.dialog(data);
	};

	ThinkPHP.error=function(msg){
		data={title:"错误",content:msg,okValue:"确定",ok:function(){}};
		$.dialog(data);
	};

})(window);

(function($){
//设置(div）放在窗口中间
$.fn.setmiddle = function() {
	var dl = $(document).scrollLeft(),
		dt = $(document).scrollTop(),
		ww = $(window).width(),
		wh = $(window).height(),
		ow = $(this).width(),
		oh = $(this).height(),
		left = (ww - ow) / 2 + dl,
		top = (oh < 4 * wh / 7 ? wh * 0.382 - oh / 2 : (wh - oh) / 2) + dt;
	$(this).css({
		left: Math.max(left, dl) + 'px',
		top: Math.max(top, dt) + 'px'
	});
	return this;
};
})(jQuery);
//提示小框
;(function(win) {
	win.ThinkPHP = win.ThinkPHP || {};
	//提示信息//success alert error
	ThinkPHP.tip = function(msg,options) {
		var settings = {
			content: msg,
			icon: 'alert',
			time: 1500,
			close: false,
			end: null,
			zindex: 9999999
		};
		if (options) {
			$.extend(settings, options);
		}

		if (settings.close) {
			$(".tipbox").hide();
			return;
		}
		if (!$('.tipbox')[0]) {
			$('body').append('<div class="tipbox"><div class="tip-l"></div><div class="tip-c"></div><div class="tip-r"></div></div>');
			$('.tipbox').css('z-index', parseInt(settings.zindex));
		}
		$('.tipbox').attr('class', 'tipbox tip-' + settings.icon);
		$('.tipbox .tip-c').html(settings.content);
		$('.tipbox').css('z-index', parseInt($('.tipbox').css('z-index')) + 1).setmiddle().show();

		if (settings.time > 0) {
			setTimeout(function() {
				$(".tipbox").fadeOut()

				if (typeof(settings.end) == 'function') {
					settings.end();
				}
			}, settings.time);
		}
	};

	ThinkPHP.tip_success=function(msg){
		ThinkPHP.tip(msg,{icon:'success'});
	};

	ThinkPHP.tip_error=function(msg){
		ThinkPHP.tip(msg,{icon:'error'});
	};


	ThinkPHP.tip_alert=function(msg){
		ThinkPHP.tip(msg,{icon:'alert'});
	};

})(window);

(function(win){
   win.ThinkPHP = win.ThinkPHP || {};
   win.think=win.ThinkPHP;
})(window);

